package cn.ittaoli.movie.controller;

import cn.ittaoli.movie.model.Admin;
import cn.ittaoli.movie.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by lub_lenovo on 2017/11/2.
 */
@RequestMapping("/admin")
@Controller
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("/add/menu/{menu}")
    public String add(@PathVariable("menu") String menu,Model model){
        model.addAttribute("menu",menu);
        return "/admin/admin_add";
    }

    @RequestMapping("/doAdd")
    @ResponseBody
    public Integer doAdd(Admin admin){
        Integer res=adminService.add(admin);
        return res;
    }

    @RequestMapping("/list/menu/{menu}")
    public String list(@PathVariable("menu") String menu,Model model){
        List<Admin> admins=adminService.getList();
        model.addAttribute("admins",admins);
        model.addAttribute("menu",menu);
        return "/admin/admin_list";
    }
}
